<template>
  <!-- 页面-组织架构-选择公司弹框 -->
  <div style="height:300px" class="selectCompany-page">
    <!-- 搜索区域 -->
    <SelfAdaption>
      <Form
        :model="searchForm"
        ref="searchForm"
        slot="adaption-bar"
        label-position="top"
        class="ivu-form-no-margin-bottom"
        inline
      >
        <!-- 公司编码 -->
        <Form-item prop="companyCode" :label="$t('module.orgManage.companyCode')">
          <Input
            type="text"
            :maxlength="50"
            v-model.trim="searchForm.companyCode"
            :placeholder="$t('module.orgManage.pleaseInput')"
            
            @on-enter="search"
          ></Input>
        </Form-item>
        <!-- 公司名称 -->
        <Form-item prop="companyName" :label="$t('module.orgManage.companyName')">
          <Input
            type="text"
            :maxlength="50"
            v-model.trim="searchForm.companyName"
            :placeholder="$t('module.orgManage.pleaseInput')"
            
            @on-enter="search"
          ></Input>
        </Form-item>

        <!-- 查询\重置按钮 -->
        <Form-item prop="button" class="search-solt-btn">  
          <RPButton optType="search" @click="search" />
          <RPButton optType="reset" @click="reset" />
        </Form-item> 
      </Form>
    </SelfAdaption>
    <InnerPageTable ref="relectCompanyTable" :config="pageTableConfig"> 
      <!-- handler bar 查询/重置-->
      <!--
      <div slot="handle-bar">
        <RPButton optType="search" @click="search" />
        <RPButton optType="reset" @click="reset" />
      </div>
      -->
    </InnerPageTable>
  </div>
</template>
<script>
// import tenantAPI from "@/api/tenantApi.js";
// import { getCompanyList } from "@/api/orgApi.js";
import { getCompanyList } from "@/api/orgApi.js";
// import { CoreModuleName } from "@/const.js";
import locales from "../locales.js";
export default {
  components: {},
  props: {},
  name: "select-company",
  mixins: [locales],
  props: {
    // productId: {
    //   type: String,
    //   default: ""
    // },
    tenantCode: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      treeTypeList: {},
      productList: {},
      tenantList: {},
      searchForm: {
        // productCode: "",
        tenantCode: this.tenantCode,
        enabled: 1, //enabled:null或不传enabled字段显示所有的公司。为1时为有效公司，0为无效公司。（只要显示有效公司）
        companyCode: "", // 公司编码
        companyName: "" // 公司名称
      },
      pageTableConfig: {
        action: null,
        resource: null, //default
        customDataProcess: null, //default
        loadDataFn: getCompanyList,
        columnsFn: this.generateColumns,
        autoFirst: false, //default false
        highlightRow: true
      }
    };
  },
  computed: {},
  created: function() {
    this.$emit("SetTitle", this.$t("module.orgManage.relectCompany"));
    this.$emit("SetPageWidth", 866);
    this.$emit("SetPageActions", [
      {
        text: this.$t("module.orgManage.confirm"),
        theme: "primary",
        handle: this.confirm
      },
      {
        text: this.$t("common.close"),
        handle: () => {
          this.$emit("Close");
        }
      }
    ]);
    this.init();
  },
  beforeMount: function() {},
  mounted: function() {
    this.search(1);
  },
  beforeDestroy: function() {},
  destroyed: function() {},
  methods: {
    // 初始化
    init() {
      // this.initTreeType();
      // this.initProduct();
      // this.initTenant();
      // this.searchForm.productCode = this.productId;
      // this.searchForm.tenantCode = this.tenantCode;
    },
    // 初始化树类型
    // initTreeType() {
    //   valueSetAPI.getValueSetByCode("treeType").then(data => {
    //     for (const treeType of data) {
    //       this.treeTypeList[treeType.vsiKey] = treeType.vsiValue;
    //     }
    //   });
    // },
    // 初始化所属产品
    // initProduct() {
    //   valueSetAPI.getValueSetByCode("RC_PRODUCT").then(data => {
    //     for (const product of data) {
    //       this.productList[product.vsiKey] = product.vsiValue;
    //     }
    //   });
    // },
    // 初始化所属租户
    // initTenant() {
    //   tenantAPI.queryTenantList().then(data => {
    //     for (const tenant of data) {
    //       this.tenantList[tenant.tenantCode] = tenant.tenantName;
    //     }
    //   });
    // },
    // 查询
    search(page) {
      this.$refs["relectCompanyTable"].load(this.searchForm, page);
    },
    // 重置
    reset() {
      this.$refs["searchForm"].resetFields();
      this.search(1);
    },
    // 表格数据
    // loadData({ responseProcess, param }) {
    //   return window.$http
    //     .post(`${window.RPConfig.mgt}/tree/list/page`, param)
    //     .then(response => response.data)
    //     .then(res => responseProcess(res));
    // },
    // 表格的列
    generateColumns() {
      return [
        {
          title: this.$t("module.orgManage.companyCode"),
          key: "companyCode",
          align: "left"
        },
        {
          title: this.$t("module.orgManage.companyName"),
          key: "companyName",
          align: "left"
        },
        {
          title: this.$t("module.orgManage.companyShort"),
          key: "companyShortName",
          align: "left"
        }
      ];
    },
    // 确定
    confirm() {
      let row = this.$refs["relectCompanyTable"].getHighlightRow();
      this.$emit("Close", row);
      
    }
  },
  watch: {},
  directives: {}
};
</script>
<style lang="less">
.selectCompany-page {
  .inner-table {
    .single-table-con {
      div:nth-child(3) {
        overflow: inherit !important;
      }
    }
  }
}
</style>